package com.example.demo1.repository;

import com.example.demo1.pojo.product;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.math.BigDecimal;
import java.util.List;

public interface productRepository extends JpaRepository<product, Integer> {
    List<product> findByNameContaining(String name);
    List<product> findByCategoryId(Integer categoryId);

    List<product> findByStatus(Integer status);

    List<product> findByBrand(String brand);

    @Query("select p from product p where p.price between :minPrice and :maxPrice")
    List<product> findByPriceRange(@Param("minPrice") BigDecimal minPrice,
                                   @Param("maxPrice") BigDecimal maxPrice);

    @Query("select p from product p where p.stock > 0 and p.status = 1")
    List<product> findAvailableProducts();

    List<product> findByOrderBySalesCountDesc();

    List<product> findByOrderByCreatedAtDesc();
}
